package com.hyhy.hycloud.uaa;

import com.hyhy.hycloud.commons.web.HyCloudExceptionHandler;
import com.hyhy.hycloud.uaa.client.UaaClientConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * UAA REST配置
 *
 * @author Xuegui Yuan
 * @date 2018-09-18
 */
@Configuration
@Import({HyCloudExceptionHandler.class, UaaClientConfig.class})
public class RestConfig {

    @Bean
    @Order(0)
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        config.addAllowedMethod("*");
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }
}
